<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.org/ui">

<h:head>
	<title>Administrador</title>
	<!-- Le styles -->
	<link href="../assets/css/style5.css" rel="stylesheet" />

</h:head>

<h:body onload="$();">
	<div id="wrapper" align="center">
		<div id="MainConteiner">

			<div id="header_">
				<ui:insert name="header">
					<ui:include src="headerAdmin.xhtml" />
				</ui:insert>
			</div>



			<div id="MainContentConteiner">
				<br />
				<h3>Criar Notícia</h3>
				<!-- form de inserção-->

				<h:form>


					<h:outputLabel value="Título:" />
					<h:inputText value="#{newsMBean.noticia.title}" required="true"
						requiredMessage="Título obrigatório" />


					<br />
					<h:outputLabel value="Conteúdo:" />
					<p:editor id="editor" value="#{newsMBean.noticia.content}"
						width="700" required="true" requiredMessage="Conteúdo obrigatório" />
					<p:dialog header="Content" widgetVar="dlg" showEffect="fade"
						hideEffect="fade" modal="true">
						<h:outputText id="display" value="#{newsMBean.noticia.content}"
							escape="false" />
					</p:dialog>


					<td><h:commandButton value="Salvar!"
							action="#{newsMBean.save}" /></td>

				</h:form>

				<h:form enctype="multipart/form-data">

					<p:fileUpload
						fileUploadListener="#{newsMBean.handleFileUpload}"
						mode="advanced" update="messages" sizeLimit="1000000"
						allowTypes="/(\.|\/)(gif|jpe?g|png)$/" />
						
					<p:growl id="messages" showDetail="true" />

				</h:form>


				<p>Abaixo é exibida uma lista com todos as notícias cadastradas
					no sistema. Você pode editá-las, excluí-las ou buscá-las através da
					tabela abaixo:</p>


				<h:form id="formMessages">
					<p:growl id="messages" widgetVar="messages" showDetail="true"
						life="5000" sticky="false" autoUpdate="true" />
				</h:form>
				<h:form id="formPrincipal">
					<p:dataTable value="#{newsMBean.todasNoticias}" var="item"
						selection="#{newsMBean.noticiaselecionada}" selectionMode="single"
						rowKey="#{item.id}" emptyMessage="Nenhuma noticia encontrada!"
						style="margin-top: 5px;">

						<f:facet name="header">
                    Clique no item para selecion&aacute;-lo
                </f:facet>
						<p:column headerText="Data"
							style="text-align: center; width: 40px;">
							<h:outputText value="#{item.date}" />
						</p:column>
						<p:column headerText="T&iacute;tulo"
							style="text-align: center; width: 40px;">
							<h:outputText value="#{item.title}" />
						</p:column>

						<f:facet name="footer">
							<p:commandButton id="viewButton" value="Mostrar noticia"
								icon="ui-icon-search" update=":formPrincipal:dialogx"
								oncomplete="newsDialog.show()" />


						</f:facet>
						<f:facet name="footer">
							<p:commandButton id="viewButton2" value="Deletar Noticia"
								icon="ui-icon-search" update=":formPrincipal:dialogdel"
								oncomplete="delDialog.show()" />
						</f:facet>

						<f:facet name="footer">
							<p:commandButton id="viewButton3" value="Atualizar Noticia"
								icon="ui-icon-search" action="#{newsMBean.paginaEditar()}" />

						</f:facet>
					</p:dataTable>


					<p:dialog id="dialogx" header="Noticia selecionada"
						widgetVar="newsDialog" resizable="false" width="400"
						showEffect="clip" hideEffect="fold">
						<h:panelGrid id="display" columns="2" cellpadding="4">

							<h:outputText value="Título:" />
							<h:outputText value="#{newsMBean.noticiaselecionada.title}" />

							<h:outputText value="Conteúdo:" />
							<h:outputText value="#{newsMBean.noticiaselecionada.content}" />

						</h:panelGrid>

					</p:dialog>




					<p:dialog id="dialogdel" header="Tem certeza que deseja apagar?"
						widgetVar="delDialog" resizable="false" width="400"
						showEffect="clip" hideEffect="fold">

						<h:panelGrid id="display23" columns="2" cellpadding="4">

							<h:commandButton value="Deletar" action="#{newsMBean.delete}" />

						</h:panelGrid>
					</p:dialog>

				</h:form>
			</div>

			<div id="footer">
				<ui:insert name="footer">
					<ui:include src="../footer.xhtml" />
				</ui:insert>
			</div>
		</div>

	</div>

</h:body>
</html>




